/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.bomt.domain.vo;

import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.HeadFontStyle;
import com.comac.ins.bomt.domain.DetailStandardBom;
import com.comac.ins.common.core.utils.ValidatorUtils;
import io.github.linpeilie.annotations.AutoMapper;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

/**
 * 标准装机清单明细
 *
 * @author zhanghongyi
 * @date 2024 /8/5 16:06
 * @description DetailStandardBomVo
 */
@Data
@ExcelIgnoreUnannotated
@AutoMapper(target = DetailStandardBom.class)
@HeadFontStyle(fontHeightInPoints = 12)
public class DetailStandardBomVo {
    /**
     * Id
     */
    private Long id;
    /**
     * 机型
     */
    private String aircraftModel;
    /**
     * 跟踪Id（用于标记产出数据的业务流程Id）
     */

    private String track;
    /**
     * 子跟踪Id（用于标记产出的业务流程步骤）
     */
    private String subTrack;
    /**
     * ATA 100
     */
    private String ata;
    /**
     * 主分组类型
     */
    private String groupType;
    /**
     * 子分组类型
     */
    private String subGroupType;
    /**
     * 全路径图号
     */
    private String fullCodePath;
    /**
     * 顺序
     */
    private Long ord;
    /**
     * 层级
     */
    @ExcelProperty(value = "层级", index = 0)
    @NotBlank(message = "层级不能为空")
    private String level;
    /**
     * 图号
     */
    @ExcelProperty(value = "图号", index = 1)
    @NotBlank(message = "图号不能为空")
    private String code;
    /**
     * 名称
     */
    @ExcelProperty(value = "名称", index = 2)
    private String name;
    /**
     * 版次
     */
    @ExcelProperty(value = "版次", index = 3)
    @NotBlank(message = "版次不能为空")
    private String version;
    /**
     * 部段
     */
    @ExcelProperty(value = "部段", index = 4)
    private String sectionName;
    /**
     * 数量
     */
    @ExcelProperty(value = "数量", index = 5)
    @NotNull(message = "数量不能为空")
    private Integer cnt;
    /**
     * 备注
     */
    private String note;

    /**
     * 根据原始装机清单明细创建标准装机清单明细
     *
     * @param originalBomVo the original bom vo
     * @param aircraftModel the aircraft model
     * @param fullCodePath  the full code path
     * @param groupType     the group type
     * @param batchNo       the batch no
     * @return the detail standard bom vo
     */
    public static DetailStandardBomVo createFromOriginalBom(DetailOriginalV2BomVo originalBomVo, String aircraftModel, String fullCodePath, String groupType, String batchNo) {
        DetailStandardBomVo result = new DetailStandardBomVo();
        //业务必须字段
        result.setLevel(StringUtils.strip(originalBomVo.getLevel()));
        result.setCode(StringUtils.strip(originalBomVo.getCode()));
        result.setName(StringUtils.strip(originalBomVo.getName()));
        String ver = StringUtils.strip(originalBomVo.getVersion());
        result.setVersion(StringUtils.isBlank(ver) || StringUtils.equals(ver, "N/A") ? "A" : ver);
        result.setSectionName(StringUtils.strip(originalBomVo.getSection()));
        String ct = StringUtils.strip(originalBomVo.getCnt());
        result.setCnt(StringUtils.isNumeric(ct) ? Integer.parseInt(originalBomVo.getCnt()) : 1);
        //额外增加的字段
        result.setAircraftModel(aircraftModel);
        result.setTrack(batchNo);
        result.setGroupType(groupType);
        result.setFullCodePath(fullCodePath);
        result.setAta(originalBomVo.getAta());
        return result;
    }

    /**
     * 参数检查
     */
    public void checkParam() {
        ValidatorUtils.validate(this);
    }
}
